package com.data.service.manage.impl;

import com.data.domain.manage.Netroundinfo;
import com.data.domain.manage.NetroundinfoCriteria;
import com.data.mapper.manage.NetroundinfoMapper;
import com.data.model.ManagerModel;
import com.data.service.manage.NetroundinfoService;
import com.data.utill.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service(value = "netroundinfoService")
public class NetroundinfoServiceImpl implements NetroundinfoService {

    @Autowired
    private NetroundinfoMapper netroundinfoMapper;

    @Override
    public List<Netroundinfo> getNetroundinfo(ManagerModel managerModel) {
        NetroundinfoCriteria netroundinfoCriteria=new NetroundinfoCriteria();
        NetroundinfoCriteria.Criteria criteria=netroundinfoCriteria.createCriteria();
        if(StringUtils.isNoNullString(managerModel.getNetround())){
            criteria.andNetroundEqualTo(Short.parseShort(managerModel.getNetround()));
        }
        netroundinfoCriteria.setOrderByClause("netround asc");
        return netroundinfoMapper.selectByExample(netroundinfoCriteria);
    }
    /**
     * 轧差场次信息插入
     * @param managerModel
     * @return
     */
    @Override
    public int insertNetroundinfo(ManagerModel managerModel) {
        NetroundinfoCriteria netroundinfoCriteria=new NetroundinfoCriteria();
        Netroundinfo data = new Netroundinfo();
        data.setNetround(Short.parseShort(managerModel.getNetround()));
        data.setNettime(Integer.parseInt(managerModel.getNettime()));
        return netroundinfoMapper.insertSelective(data);
    }

    /**
     * 轧差场次信息表修改
     * @param managerModel
     * @return
     */
    @Override
    public int modifyNetroundinfo(ManagerModel managerModel ,String id) {
        NetroundinfoCriteria netroundinfoCriteria=new NetroundinfoCriteria();
        netroundinfoCriteria.createCriteria().andNetroundEqualTo(Short.parseShort(id));
        Netroundinfo data = new Netroundinfo();
//        data.setNetround(Short.parseShort(managerModel.getNetround()));
        data.setNettime(Integer.parseInt(managerModel.getNettime()));
        return netroundinfoMapper.updateByExampleSelective(data,netroundinfoCriteria);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Override
    public Netroundinfo getNetroundinfoById(String  id) {
        NetroundinfoCriteria netroundinfoCriteria=new NetroundinfoCriteria();
        netroundinfoCriteria.createCriteria().andNetroundEqualTo(Short.parseShort(id));
        List<Netroundinfo> data = netroundinfoMapper.selectByExample(netroundinfoCriteria);
        if (null!=data) {
            return data.get(0);
        }else{
            return null;
        }
    }
}
